package com.ruoyi.personnel.salary.payroll.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.personnel.salary.payroll.domain.PayrollCond;
import com.ruoyi.personnel.salary.payroll.domain.PayrollDomain;
import com.ruoyi.personnel.salary.payroll.domain.PayrollDto;
import com.ruoyi.personnel.salary.payroll.service.IPayrollService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/salary/payroll")
@Api(value = "工资表模块", tags = "工资表接口")
public class PayrollController extends BaseController {
    @Autowired
    private IPayrollService payrollService;

    /**
     * 获取工资表列表
     * @return
     */
    @ApiOperationSupport(includeParameters = {"PayrollCond.payrollId", "PayrollCond.staffId", "PayrollCond.createTime"})
    @ApiOperation(value = "获取工资表列表",notes = "查询所有工资表信息")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody PayrollCond cond) {
        startPage();
        List<PayrollDto> payrollList = payrollService.selectPayrollList(cond);
        return getDataTable(payrollList);
    }

    /**
     * 新增工资表
     *
     * @param payroll
     * @return
     */
    @ApiOperation(value = "新增工资表记录", notes = "新增工资表信息")
    @ApiImplicitParam(name = "payroll", value = "新增工资表", dataType = "PayrollDomain")
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody PayrollDomain payroll) {
        return toAjax(payrollService.insertPayroll(payroll));
    }

    /**
     * 修改工资计算记录
     *
     * @param payroll
     * @return
     */
    @ApiOperation(value = "修改工资表", notes = "修改工资表信息")
    @ApiImplicitParam(name = "payroll", value = "修改工资表", dataType = "PayrollDomain")
    @PostMapping("/edit")
    public AjaxResult edit(@Validated @RequestBody PayrollDomain payroll) {
        return toAjax(payrollService.updatePayroll(payroll));
    }

    /**
     * 删除工资计算记录
     * 仅修改删除标志位
     *
     * @param payroll
     * @return
     */
    @ApiOperation(value = "删除工资表", notes = "删除工资表,仅删除标志位")
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody PayrollDomain payroll) {
        return toAjax(payrollService.updatePayrollDeleteFlag(payroll));
    }
}
